﻿//-----------------------------------------------------------------------
// <copyright file="Quantify.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the Quantify class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Engine.EngineOperation
{
    using Tuples;

    /// <summary>
    /// Represents a quantification engine operation.   Manages the deferred execution of qunatification.
    /// </summary>
    internal class Quantify : EngineOperation<object>
    {
        /// <summary>
        /// Initializes a new instance of the Quantify class.
        /// </summary>
        /// <param name="session">The current tuple store session.</param>
        public Quantify(TupleStoreSession session)
        {
            this.session = session;
            this.data = null;
        }

        #region IEngineOperation Members

        /// <summary>
        /// Performs the engine operation.
        /// </summary>
        /// <param name="facts">Ignored in this implementation.</param>
        /// <returns>Indicates if the engine should start a new match-resolve-do cycle.</returns>
        public override bool Perform(ref object[] facts)
        {
            // Do deferred quantifications
            while (this.session.QuantificationQueue.Count > 0)
            {
                var qbl = this.session.QuantificationQueue.Dequeue();
                qbl.ExecuteSequenceForQuantification();
            }

            return false;
        }

        #endregion
    }
}
